package com.mystore.util;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class ParseXmlUtil {
    private static  Document docXml;


    /**
     * 获取document对象
     */
    static {
        SAXReader reader = new SAXReader();
        try {
            docXml = reader.read(ParseXmlUtil.class.getClassLoader().getResourceAsStream("/config.xml"));
        } catch (DocumentException e) {
            System.out.println("read failed");
            e.printStackTrace();
        }
    }

    /**
     * 获取类路径
     * @param name
     * @return
     */
    public String getAction(String name){
        Element element= (Element) docXml.selectSingleNode("//config/actions/action[@name='"+name+"']");
        return element.attributeValue("class");

    }

}
